home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / ixemul / sdk / man / cat4 / ip.0 < prev    next >
Encoding:
Text File  |  1998-06-15  |  9.5 KB  |  213 lines

  1.  
  2. IP(4)                      UNIX Programmer's Manual                      IP(4)
  3.  
  4. NNAAMMEE
  5.      iipp - Internet Protocol
  6.  
  7. SSYYNNOOPPSSIISS
  8.      ##iinncclluuddee <<ssyyss//ssoocckkeett..hh>>
  9.      ##iinncclluuddee <<nneettiinneett//iinn..hh>>
  10.  
  11.      _i_n_t
  12.      ssoocckkeett(_A_F___I_N_E_T, _S_O_C_K___R_A_W, _p_r_o_t_o)
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.      IP is the transport layer protocol used by the Internet protocol family.
  16.      Options may be set at the IP level when using higher-level protocols that
  17.      are based on IP (such as TCP and UDP). It may also be accessed through a
  18.      ``raw socket'' when developing new protocols, or special-purpose applica-
  19.      tions.
  20.  
  21.      There are several IP-level setsockopt(2)/ getsockopt(2) options.
  22.      IP_OPTIONS may be used to provide IP options to be transmitted in the IP
  23.      header of each outgoing packet or to examine the header options on incom-
  24.      ing packets.  IP options may be used with any socket type in the Internet
  25.      family.  The format of IP options to be sent is that specified by the IP
  26.      protocol specification (RFC-791), with one exception: the list of ad-
  27.      dresses for Source Route options must include the first-hop gateway at
  28.      the beginning of the list of gateways.  The first-hop gateway address
  29.      will be extracted from the option list and the size adjusted accordingly
  30.      before use.  To disable previously specified options, use a zero-length
  31.      buffer:
  32.  
  33.      setsockopt(s, IPPROTO_IP, IP_OPTIONS, NULL, 0);
  34.  
  35.      IP_TOS and IP_TTL may be used to set the type-of-service and time-to-live
  36.      fields in the IP header for SOCK_STREAM and SOCK_DGRAM sockets. For exam-
  37.      ple,
  38.  
  39.      int tos = IPTOS_LOWDELAY;       /* see <netinet/in.h> */
  40.      setsockopt(s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos));
  41.  
  42.      int ttl = 60;                   /* max = 255 */
  43.      setsockopt(s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
  44.  
  45.      If the IP_RECVDSTADDR option is enabled on a SOCK_DGRAM socket, the
  46.      recvmsg call will return the destination IP address for a UDP datagram.
  47.      The msg_control field in the msghdr structure points to a buffer that
  48.      contains a cmsghdr structure followed by the IP address.  The cmsghdr
  49.      fields have the following values:
  50.  
  51.      cmsg_len = sizeof(struct in_addr)
  52.      cmsg_level = IPPROTO_IP
  53.      cmsg_type = IP_RECVDSTADDR
  54.  
  55.    MMuullttiiccaasstt OOppttiioonnss
  56.  
  57.      IP multicasting is supported only on AF_INET sockets of type SOCK_DGRAM
  58.      and SOCK_RAW, and only on networks where the interface driver supports
  59.      multicasting.
  60.  
  61.      The IP_MULTICAST_TTL option changes the time-to-live (TTL) for outgoing
  62.      multicast datagrams in order to control the scope of the multicasts:
  63.  
  64.      u_char ttl;     /* range: 0 to 255, default = 1 */
  65.      setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
  66.  
  67.      Datagrams with a TTL of 1 are not forwarded beyond the local network.
  68.      Multicast datagrams with a TTL of 0 will not be transmitted on any net-
  69.      work, but may be delivered locally if the sending host belongs to the
  70.      destination group and if multicast loopback has not been disabled on the
  71.      sending socket (see below).  Multicast datagrams with TTL greater than 1
  72.      may be forwarded to other networks if a multicast router is attached to
  73.      the local network.
  74.  
  75.      For hosts with multiple interfaces, each multicast transmission is sent
  76.      from the primary network interface.  The IP_MULTICAST_IF option overrides
  77.      the default for subsequent transmissions from a given socket:
  78.  
  79.      struct in_addr addr;
  80.      setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF, &addr, sizeof(addr));
  81.  
  82.      where "addr" is the local IP address of the desired interface or
  83.      INADDR_ANY to specify the default interface.  An interface's local IP ad-
  84.      dress and multicast capability can be obtained via the SIOCGIFCONF and
  85.      SIOCGIFFLAGS ioctls.  Normal applications should not need to use this op-
  86.      tion.
  87.  
  88.      If a multicast datagram is sent to a group to which the sending host it-
  89.      self belongs (on the outgoing interface), a copy of the datagram is, by
  90.      default, looped back by the IP layer for local delivery.  The
  91.      IP_MULTICAST_LOOP option gives the sender explicit control over whether
  92.      or not subsequent datagrams are looped back:
  93.  
  94.      u_char loop;    /* 0 = disable, 1 = enable (default) */
  95.      setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop));
  96.  
  97.      This option improves performance for applications that may have no more
  98.      than one instance on a single host (such as a router demon), by eliminat-
  99.      ing the overhead of receiving their own transmissions.  It should gener-
  100.      ally not be used by applications for which there may be more than one in-
  101.      stance on a single host (such as a conferencing program) or for which the
  102.      sender does not belong to the destination group (such as a time querying
  103.      program).
  104.  
  105.      A multicast datagram sent with an initial TTL greater than 1 may be de-
  106.      livered to the sending host on a different interface from that on which
  107.      it was sent, if the host belongs to the destination group on that other
  108.      interface.  The loopback control option has no effect on such delivery.
  109.  
  110.      A host must become a member of a multicast group before it can receive
  111.      datagrams sent to the group.  To join a multicast group, use the
  112.      IP_ADD_MEMBERSHIP option:
  113.  
  114.      struct ip_mreq mreq;
  115.      setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
  116.  
  117.      where _m_r_e_q is the following structure:
  118.  
  119.      struct ip_mreq {
  120.          struct in_addr imr_multiaddr; /* multicast group to join */
  121.          struct in_addr imr_interface; /* interface to join on */
  122.      }
  123.  
  124.      imr_interface should be INADDR_ANY to choose the default multicast inter-
  125.      face, or the IP address of a particular multicast-capable interface if
  126.      the host is multihomed.  Membership is associated with a single inter-
  127.      face; programs running on multihomed hosts may need to join the same
  128.      group on more than one interface.  Up to IP_MAX_MEMBERSHIPS (currently
  129.      20) memberships may be added on a single socket.
  130.  
  131.  
  132.      To drop a membership, use:
  133.  
  134.      struct ip_mreq mreq;
  135.      setsockopt(s, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
  136.  
  137.      where _m_r_e_q contains the same values as used to add the membership.  Mem-
  138.      berships are dropped when the socket is closed or the process exits.
  139.  
  140.    RRaaww IIPP SSoocckkeettss
  141.  
  142.      Raw IP sockets are connectionless, and are normally used with the sendto
  143.      and recvfrom calls, though the connect(2) call may also be used to fix
  144.      the destination for future packets (in which case the read(2) or recv(2)
  145.      and write(2) or send(2) system calls may be used).
  146.  
  147.      If _p_r_o_t_o is 0, the default protocol IPPROTO_RAW is used for outgoing
  148.      packets, and only incoming packets destined for that protocol are re-
  149.      ceived.  If _p_r_o_t_o is non-zero, that protocol number will be used on out-
  150.      going packets and to filter incoming packets.
  151.  
  152.      Outgoing packets automatically have an IP header prepended to them (based
  153.      on the destination address and the protocol number the socket is created
  154.      with), unless the IP_HDRINCL option has been set.  Incoming packets are
  155.      received with IP header and options intact.
  156.  
  157.      IP_HDRINCL indicates the complete IP header is included with the data and
  158.      may be used only with the SOCK_RAW type.
  159.  
  160.      #include <netinet/ip.h>
  161.  
  162.      int hincl = 1;                  /* 1 = on, 0 = off */
  163.      setsockopt(s, IPPROTO_IP, IP_HDRINCL, &hincl, sizeof(hincl));
  164.  
  165.      Unlike previous BSD releases, the program must set all the fields of the
  166.      IP header, including the following:
  167.  
  168.      ip->ip_v = IPVERSION;
  169.      ip->ip_hl = hlen >> 2;
  170.      ip->ip_id = 0;  /* 0 means kernel set appropriate value */
  171.      ip->ip_off = offset;
  172.      If the header source address is set to INADDR_ANY, the kernel will choose
  173.      an appropriate address.
  174.  
  175. DDIIAAGGNNOOSSTTIICCSS
  176.      A socket operation may fail with one of the following errors returned:
  177.  
  178.      [EISCONN]        when trying to establish a connection on a socket which
  179.                       already has one, or when trying to send a datagram with
  180.                       the destination address specified and the socket is al-
  181.                       ready connected;
  182.  
  183.      [ENOTCONN]       when trying to send a datagram, but no destination ad-
  184.                       dress is specified, and the socket hasn't been connect-
  185.                       ed;
  186.  
  187.      [ENOBUFS]        when the system runs out of memory for an internal data
  188.                       structure;
  189.  
  190.      [EADDRNOTAVAIL]  when an attempt is made to create a socket with a net-
  191.                       work address for which no network interface exists.
  192.  
  193.      [EACESS]         when an attempt is made to create a raw IP socket by a
  194.                       non-privileged process.
  195.  
  196.      The following errors specific to IP may occur when setting or getting IP
  197.  
  198.      options:
  199.  
  200.      [EINVAL]         An unknown socket option name was given.
  201.  
  202.      [EINVAL]         The IP option field was improperly formed; an option
  203.                       field was shorter than the minimum value or longer than
  204.                       the option buffer provided.
  205.  
  206. SSEEEE AALLSSOO
  207.      getsockopt(2),  send(2),  recv(2),  intro(4),  icmp(4),  inet(4)
  208.  
  209. HHIISSTTOORRYY
  210.      The iipp protocol appeared in 4.2BSD.
  211.  
  212. 4.2 Berkeley Distribution      November 30, 1993                             4
  213.